//
//  HZCartEmptyView.m
//  app
//
//  Created by 刘华舟 on 15/5/5.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZCartEmptyView.h"
#import "UIImageView+URL.h"

#import "HZImageSourceConstant.h"

static const NSInteger kCartEmptyDescpLabelHeight = 120;
static const CGFloat kCartEmptyLoginBtnHeight = 60/2;
static const CGFloat kCartEmptyLoginBtnWidth = 160/2;
static const NSInteger kCartEmptyPicHeight = 240;
static const NSInteger kCartEmptyShortDescpLabelHeight = 80;
static const CGFloat kCartEmptyGetAroundBtnHeight = 60/2;
static const CGFloat kCartEmptyGetAroundBtnWidth = 160/2;
static const NSInteger kCartEmptyMargin = 24;
static const NSInteger kCartEmptyPadding = 40;

static NSString * const kCartEmptyDescpText = @"登录后，即可显示您已添加的商品";
static NSString * const kCartEmptyShortDescpText = @"购物车空空如也";


@interface HZCartEmptyView()

@property (strong, nonatomic) UILabel *descriptionLabel;
@property (strong, nonatomic) UIButton *loginBtn;
@property (strong, nonatomic) UIView *backView;
@property (strong, nonatomic) UIImageView *picImgView;
@property (strong, nonatomic) UILabel *shortDesLabel;
@property (strong, nonatomic) UIButton *getArountBtn;

@end

@implementation HZCartEmptyView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = HZ_MALL_M_LIGHT_GRAY_BACKGROUND_COLOR;
        
        //短描述
        self.shortDesLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT fy:UB_CENTER uy:-kCartEmptyShortDescpLabelHeight],
                                                                        [self.ubo fw:UB_WIDTH uh:kCartEmptyShortDescpLabelHeight])];
        self.shortDesLabel.text = kCartEmptyShortDescpText;
        self.shortDesLabel.textAlignment = NSTextAlignmentCenter;
        self.shortDesLabel.font = JKAppGlobleFontContentText;
        self.shortDesLabel.textColor = HZ_MALL_TEXT_GRAY_COLOR;
        [self addSubview:self.shortDesLabel];
        
        //背景图片
        self.picImgView = [[UIImageView alloc] initWithFrame:CGRectOf([self.shortDesLabel.ufo fx:UB_CENTER ux:-kCartEmptyPicHeight/2 fy:UB_TOP uy:-kCartEmptyPicHeight] ,
                                                                      [self.ubo uw:kCartEmptyPicHeight uh:kCartEmptyPicHeight])];
        [self.picImgView setImage:[UIImage imageNamed:kImageMallLogo]];
        [self addSubview:self.picImgView];
        
        //登录按钮
        self.getArountBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.shortDesLabel.ufo fx:UB_CENTER ox:-kCartEmptyGetAroundBtnWidth/2 fy:UB_BOTTOM],
                                                                 [self.ubo ow:kCartEmptyGetAroundBtnWidth oh:kCartEmptyGetAroundBtnHeight])];
        [self.getArountBtn setTitle:@"先逛逛" forState:UIControlStateNormal];
        [self.getArountBtn setTitleColor:HZ_MALL_TEXT_M_LIGHTGRAY_COLOR forState:UIControlStateNormal];
        [self.getArountBtn.titleLabel setFont:JKAppGlobleFontContentText];
        [self.getArountBtn setBackgroundColor:HZ_CLEAR_COLOR];
        self.getArountBtn.layer.masksToBounds = YES;
        self.getArountBtn.layer.cornerRadius = [self.ubo ow:4];
        self.getArountBtn.layer.borderColor = HZ_MALL_TEXT_M_LIGHTGRAY_COLOR.CGColor;
        self.getArountBtn.layer.borderWidth = [self.ubo pw:2];
        [self.getArountBtn addTarget:self action:@selector(getArountBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.getArountBtn];
        
        
        //背景
        self.backView = [[UIView alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP],
                                                               [self.ubo fw:UB_WIDTH uh:kCartEmptyDescpLabelHeight])];
        self.backView.backgroundColor = HZ_WHITE_COLOR;
        [self addSubview:self.backView];
        
        //长描述
        self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.backView.ubo fx:UB_LEFT ux:2*kCartEmptyMargin fy:UB_TOP],
                                                                        [self.ubo fw:UB_WIDTH uw:-(kCartEmptyMargin*3 + kCartEmptyPadding ) ow:-kCartEmptyLoginBtnWidth uh:kCartEmptyDescpLabelHeight])];
        self.descriptionLabel.text = [NSString stringWithString:kCartEmptyDescpText];
        self.descriptionLabel.textAlignment = NSTextAlignmentLeft;
        self.descriptionLabel.numberOfLines = 2;
        self.descriptionLabel.font = JKAppGlobleFontMinTagText;
        self.descriptionLabel.textColor = HZ_MALL_TEXT_M_LIGHTGRAY_COLOR;
        [self.backView addSubview:self.descriptionLabel];
        
        //登录按钮
        self.loginBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.descriptionLabel.ufo fx:UB_RIGHT ux:kCartEmptyPadding fy:UB_CENTER oy:-kCartEmptyLoginBtnHeight/2],
                                                                 [self.descriptionLabel.ubo ow:kCartEmptyLoginBtnWidth oh:kCartEmptyLoginBtnHeight])];
        [self.loginBtn setTitle:@"立即登录" forState:UIControlStateNormal];
        [self.loginBtn setTitleColor:HZ_MALL_MAIN_THEME_ORANGE forState:UIControlStateNormal];
        [self.loginBtn.titleLabel setFont:JKAppGlobleFontContentText];
        [self.loginBtn setBackgroundColor:HZ_CLEAR_COLOR];
        self.loginBtn.layer.masksToBounds = YES;
        self.loginBtn.layer.cornerRadius = [self.ubo uw:8];
        self.loginBtn.layer.borderColor = HZ_MALL_MAIN_THEME_ORANGE.CGColor;
        self.loginBtn.layer.borderWidth = [self.ubo pw:2];
        [self.loginBtn addTarget:self action:@selector(loginBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:self.loginBtn];
        
    }
    return self;
}

//点击登录按钮
- (void)loginBtnOnClick{
    
    HZLog(@"点击登录按钮");
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(cartEmptyViewLoginWithView:)]) {
        [self.delegate cartEmptyViewLoginWithView:self];
    }
    
    
}

//点击先逛逛
- (void)getArountBtnOnClick{
    HZLog(@"点击先逛逛");
    if (self.delegate && [self.delegate respondsToSelector:@selector(cartEmptyViewGetAroundWithView:)]) {
        [self.delegate cartEmptyViewGetAroundWithView:self];
    }
}

- (void)showWithLoginBtn:(BOOL)showBtn{
    self.backView.hidden = !showBtn;
    self.hidden = NO;
}
- (void)hide{
    self.hidden = YES;
}

@end
